﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataAccess;
using System.Web.Security;
public partial class ExpertManager_InsertExpert : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void BtnReg_Click(object sender, EventArgs e)
    {
        
     try
        {

            if (Membership.GetUser(Txusername.Text) == null)
            {
                Membership.CreateUser(Txusername.Text, Txpass.Text);
                Roles.AddUserToRole(Txusername.Text, "Expert");
                ProfileCommon p = Profile.GetProfile(Txusername.Text);
                TblExpert exp = new TblExpert();
                exp.Name = Txname.Text;
                exp.Family = txfamily.Text;
                exp.Address = Txaddress.Text;
                exp.Mobile = TxMobile.Text;
                exp.Telephone = Txtele.Text;
                exp.NationalCode = TxNationCode.Text;
                exp.ProvinceId = Convert.ToInt32(DropDownList1.SelectedItem.Value);
                exp.EmailAddress = Txmail.Text;
                exp.UserName = Txusername.Text;
                p.Common.username = Txusername.Text;
                p.Common.Email = Txmail.Text;
                p.Common.FirstName = Txname.Text;
                p.Common.LastName = txfamily.Text;
                p.Common.Category = "کارشناس";
                p.Common.Mobile = TxMobile.Text;
                p.Common.Phone = Txtele.Text;
                p.Common.Address = Txaddress.Text;
                p.Common.Status = "On";
                p.Save();
                exp.Save();
                LBLStatus.Text = "کارشناس با موفقیت اضافه شد";
                Txtele.Text = "";
                Txconf.Text = "";
                Txaddress.Text = "";
                txfamily.Text = "";
                Txmail.Text = "";
                TxMobile.Text = "";
                Txname.Text = "";
                TxNationCode.Text = "";
                Txpass.Text = "";
                Txusername.Text = "";
                
                GridView1.DataBind();
            }
            else
            {
                Lbl.Text = "نام کاربری جدید انتخاب کنید";

            }
          }
        catch {
            LBLStatus.Text = "ثبت کارشناس با ناموفقیت برخورد شد";
            
        }
       }
}